import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:leader_help/page/home/province_level/index.dart';
import 'package:leader_help/utils/util.dart';

class ProvinceLevelHeader extends GetView<ProvinceLevelController> {
  const ProvinceLevelHeader({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var state = controller.state;
    return Container(
      margin: EdgeInsets.all(10.r),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(5.r),
      ),
      child: Column(
        children: [
          Stack(
            children: [
              Positioned(
                child: Container(
                  padding: EdgeInsets.symmetric(horizontal: 10.r),
                  height: 50.r,
                  alignment: Alignment.centerLeft,
                  child: Text(
                    '对标总结',
                    style: pfSCStyle(color: ColorsUtil.red, fontSize: 15.sp),
                  ),
                ),
              ),
              Positioned.fill(
                child: Center(
                  child: Text(
                    '${state.mod.provinceName} 对标 ${state.levelMod.provinceName}',
                    style: pfSCStyle(color: ColorsUtil.red, fontSize: 15.sp),
                  ),
                ),
              )
            ],
          ),
          Container(
            height: 1,
            width: double.infinity,
            color: ColorsUtil.separator,
          ),
          getItem(
            iden: '关键\n任务',
            items: [
              ProvinceDiffItemModel(name: '两省有10项任务相同', isLack: false),
              ProvinceDiffItemModel(name: '2项任务湖北有，河南无', isLack: true),
              ProvinceDiffItemModel(name: '1项任务河南有，湖北无', isLack: false),
            ],
            callback: () {
              controller.handleTabTap(0);
            },
          ),
          getItem(
            iden: '省的\n重点',
            items: [
              ProvinceDiffItemModel(name: '两省有2项任务相同', isLack: false),
              ProvinceDiffItemModel(name: '1项任务湖北有，河南无', isLack: true),
              ProvinceDiffItemModel(name: '1项任务河南有，湖北无', isLack: false),
            ],
            callback: () {
              controller.handleTabTap(1);
            },
          ),
          getItem(
            iden: '要素\n配置',
            items: [
              ProvinceDiffItemModel(name: '湖北5项相关政策，比河南多2项', isLack: false),
              ProvinceDiffItemModel(name: '河南2项关于要素配置的政策和措施', isLack: true),
            ],
            callback: () {
              controller.handleTabTap(2);
            },
          ),
          getItem(
            iden: '营商\n环境',
            items: [
              ProvinceDiffItemModel(name: '湖北3项相关政策，比河南多1项', isLack: true),
              ProvinceDiffItemModel(name: '湖北建立有营商环境投诉平台，河南无', isLack: true),
            ],
            callback: () {
              controller.handleTabTap(3);
            },
          ),
        ],
      ),
    );
  }

  Widget getItem({
    required String iden,
    required List<ProvinceDiffItemModel> items,
    VoidCallback? callback,
  }) {
    return GestureDetector(
      onTap: callback,
      child: Container(
        padding: EdgeInsets.symmetric(vertical: 10.r),
        margin: EdgeInsets.symmetric(horizontal: 10.r),
        decoration: const BoxDecoration(
            border: Border(
          bottom: BorderSide(
            color: ColorsUtil.separator,
          ),
        )),
        child: Row(
          children: [
            Container(
              alignment: Alignment.center,
              height: items.length * 25.r,
              width: 55.r,
              margin: EdgeInsets.only(right: 10.r),
              decoration: BoxDecoration(
                color: ColorsUtil.blue,
                borderRadius: BorderRadius.circular(5.r),
              ),
              child: Text(
                iden,
                style: pfMediumStyle(color: Colors.white, fontSize: 14.sp),
              ),
            ),
            Flexible(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: items.map((e) => _getText(e)).toList(),
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget _getText(ProvinceDiffItemModel mod) {
    return Container(
      height: 25.r,
      alignment: Alignment.centerLeft,
      child: Row(
        children: [
          Icon(
            mod.isLack ? Icons.info : Icons.check_circle,
            size: 15.r,
            color: mod.isLack ? ColorsUtil.orange : ColorsUtil.green,
          ),
          SizedBox(
            width: 4.r,
          ),
          Expanded(
            child: Text(
              mod.name,
              overflow: TextOverflow.ellipsis,
              maxLines: 1,
              style: pfMediumStyle(
                  color: mod.isLack ? ColorsUtil.orange : ColorsUtil.title,
                  fontSize: 15.sp),
            ),
          )
        ],
      ),
    );
  }
}

class ProvinceDiffItemModel {
  String name;
  bool isLack;
  bool? isLack2;
  ProvinceDiffItemModel({
    required this.name,
    required this.isLack,
    this.isLack2,
  });
}
